//
//  SeePlanTableViewCell.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/27.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "SeePlanTableViewCell.h"
#import "JTCSM.h"

static CGFloat const seeplanspace = 20;

static CGFloat const seeplantop = 5;

static CGFloat const seeplanlabelheight = 50;

@interface SeePlanTableViewCell (){
    
    UILabel *nameLabel;
    
    UILabel *timeLabel;
    
    UILabel *moneyLabel;
    
    UILabel *platformlabel;
}

@end
@implementation SeePlanTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier SeePlanTableViewCellType:(SeePlanTableViewCellType)type{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        if (type == isZhangDanType) {
            nameLabel = [UILabel initWithFrame:CGRectMake(seeplanspace, seeplantop, KSCREENWidth*2/3-seeplanspace, seeplanlabelheight/2) text:@"" font:16 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
            [self.contentView addSubview:nameLabel];
            
            timeLabel = [UILabel initWithFrame:CGRectMake(seeplanspace, KVIEW_Y(nameLabel), KSCREENWidth/2-seeplanspace, seeplanlabelheight/2) text:@"" font:14 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(133, 133, 133, 1) backgroundColor:nil];
            [self.contentView addSubview:timeLabel];
            
            moneyLabel = [UILabel initWithFrame:CGRectMake(KSCREENWidth*2/3, seeplantop, KSCREENWidth/3-seeplanspace, seeplanlabelheight) text:@"" font:16 textAlignment:NSTextAlignmentRight texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
            [self.contentView addSubview:moneyLabel];
            
            [df lineViewWithHeightofTop:KVIEW_Y(moneyLabel)+seeplantop superView:self.contentView spacing:-150 color:RGBACOLOR(193, 193, 193, 1) lineHeight:1];

        }else{
            
            
            timeLabel = [UILabel initWithFrame:CGRectMake(seeplanspace, seeplantop, (KSCREENWidth-2*seeplanspace)/2, seeplanlabelheight/2) text:@"" font:13 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(133, 133, 133, 1) backgroundColor:nil];
            [self.contentView addSubview:timeLabel];
            
            
            
            nameLabel = [UILabel initWithFrame:CGRectMake(seeplanspace, KVIEW_Y(timeLabel), (KSCREENWidth-2*seeplanspace)/2, seeplanlabelheight/2) text:@"" font:13 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
            [self.contentView addSubview:nameLabel];
            
            moneyLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(nameLabel), seeplantop, (KSCREENWidth-2*seeplanspace)/2, seeplanlabelheight) text:@"" font:13 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
            [self.contentView addSubview:moneyLabel];
            
            platformlabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(moneyLabel), seeplantop, (KSCREENWidth-2*seeplanspace)/2, seeplanlabelheight/2) text:@"" font:12 textAlignment:NSTextAlignmentRight texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
            [self.contentView addSubview:platformlabel];
            [df lineViewWithHeightofTop:KVIEW_Y(nameLabel)+seeplantop superView:self.contentView spacing:-150 color:RGBACOLOR(193, 193, 193, 1) lineHeight:1];
            
        }
        
        
    }
    
    return self;
}

- (void)setvalueWithSeePlanModel:(SeePlanModel*)model SeePlanTableViewCellType:(SeePlanTableViewCellType)type{
    
    if (type == isZhangDanType) {
        
        
        nameLabel.text = model.directions;
        
        timeLabel.text = model.create_time;
        
        if ([model.money integerValue] >0) {
            moneyLabel.text = [NSString stringWithFormat:@"+%.2f",[model.money floatValue]];
            moneyLabel.textColor = RGBACOLOR(227, 72, 40, 1);
        }else{
            moneyLabel.text = [NSString stringWithFormat:@"%.2f",[model.money floatValue]];
            moneyLabel.textColor = RGBACOLOR(89, 89, 89, 1);
        }
        
        
        
    }else{
        timeLabel.font = [UIFont systemFontOfSize:16];
        timeLabel.textColor= RGBACOLOR(0, 0, 0, 1);
        timeLabel.text = [NSString stringWithFormat:@"还款：¥%.2f",[model.total_price floatValue]];
        
        
        nameLabel.textColor = RGBACOLOR(0, 0, 0, 0.6);
        nameLabel.text = [NSString stringWithFormat:@"还款日期%@",model.plan_date];
//        0待执行 1还款中 2已还款 3还款失败
        moneyLabel.font = [UIFont systemFontOfSize:16];
        moneyLabel.textColor= RGBACOLOR(255, 95, 49, 1);
        moneyLabel.textAlignment = NSTextAlignmentRight;
        switch ([model.status integerValue]) {
            case 0:
                moneyLabel.text = @"待执行";
                break;
            case 1:
                moneyLabel.text = @"还款中";
                break;
            case 2:
                moneyLabel.text = @"已还款";
                break;
            case 3:
                moneyLabel.text = @"还款失败";
                break;
                
            default:
                break;
        }
    
        
    }
    
}

- (void)setvalueWithSeePlanDetailModel:(SeePlanDetailModel*)model{
    
    
    self.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    self.contentView.backgroundColor = RGBACOLOR(241,241, 241, 1);
    timeLabel.text = @"消费金额";
    timeLabel.font = [UIFont systemFontOfSize:14];
    timeLabel.textColor = RGBACOLOR(0, 0, 0, 0.8);
    
    moneyLabel.textColor= RGBACOLOR(255, 95, 49, 1);
    moneyLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.total_price floatValue]];
    CGRect rect = [df labelHeightWithContent:moneyLabel.text height:seeplanlabelheight font:13];
    moneyLabel.frame = CGRectMake(KSCREENWidth-seeplanspace-rect.size.width, seeplantop, rect.size.width, seeplanlabelheight/2);
    nameLabel.font = [UIFont systemFontOfSize:14];
    nameLabel.textColor = RGBACOLOR(0, 0, 0, 0.5);
    switch ([model.status integerValue]) {
        case 0:
            nameLabel.text = @"消费：待执行";
            break;
        case 1:
            nameLabel.text = @"消费：还款中";
            break;
        case 2:
            nameLabel.text = @"消费：已还款";
            break;
        case 3:
            nameLabel.text = @"消费：还款失败";
            break;
            
        default:
            break;
    }
//    nameLabel.textColor = RGBACOLOR(0, 128, 0, 1);
//    [df fuwenbenLabel:nameLabel FontNumber:[UIFont systemFontOfSize:13] AndRange:NSMakeRange(0, 2) AndColor:RGBACOLOR(89, 89, 89, 1)];
    NSString *platform = [NSString stringWithFormat:@"含手续费%@元",model.platform];
    CGRect nameRect = [df labelHeightWithContent:platform height:seeplanlabelheight font:12];
    platformlabel.textColor= RGBACOLOR(0, 0, 0, 0.5);
    platformlabel.text = platform;
    
    platformlabel.frame = CGRectMake(KSCREENWidth-seeplanspace-nameRect.size.width, KVIEW_Y(moneyLabel), nameRect.size.width, seeplanlabelheight/2);
}

@end
